package com.example.demo_dongruanD.controller;

import com.example.demo_dongruanD.pojo.OverAllResult;
import com.example.demo_dongruanD.response.ApiResponse;
import com.example.demo_dongruanD.service.OverAllResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class OverAllResultController {

    @Autowired
    private OverAllResultService overAllResultService;

    @PostMapping("/overall/result")
    public ApiResponse<List<OverAllResult>> getOverallResults(@RequestBody Map<String, Integer> request) {
        Integer orderId = request.get("orderId");
        if (orderId == null) {
            return new ApiResponse<>(400, "orderId is required");
        }

        List<OverAllResult> results = overAllResultService.getOverallResultsByOrderId(orderId);
        return new ApiResponse<>(200, "Success", results, results.size());
    }
}
